from hashlib import md5
salt_string = 'xxxx'  # 加盐，防止撞库获得密码明文


def encrypt_md5(data_string):
    # 创建md5对象,加盐
    md5_obj = md5(salt_string.encode('utf-8'))

    # 这里必须用encode()函数对字符串进行编码，不然会报 TypeError: Unicode-objects must be encoded before hashing
    md5_obj.update(data_string.encode(encoding='utf-8'))

    # 加密
    return md5_obj.hexdigest()


# 调用
if __name__ == '__main__':
    print(encrypt_md5('000000'))
